﻿using Common.Communication;
using DeviceBase;
using DeviceBase.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace Scanner.Core
{
    /// <summary>
    /// 霍尼韦尔扫码器（支持HF800，等...）
    /// 必须去下载软件“DataMax”去设置‘工作模式’为‘外部触发’；解码设置：触发超时时间设置为5000。
    /// 官网：https://sps.honeywell.com/us/en/products/productivity/barcode-scanners/fixed-mount/hf800
    /// 文档：https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/ppr/en-us/public/products/barcode-scanners/fixed-mount/hf800/sps-ppr-hf800-en-qs.pdf?download=false
    /// 下载软件：https://hsmftp.honeywell.com/
    /// </summary>
    public class HoneywellSocket : SocketClientBase, IScanner
    {
        public string Name { get; set; }
        public HoneywellSocket(string name, string ip, int port, int timeout = 1500) : base(ip, port, timeout)
        {
            Name = name;
        }
        /// <summary>
        /// 在外部触发模式下执行一次
        /// </summary>
        /// <param name="timeout">保持时长（毫秒），填写解码设置：触发超时时间设置的值</param>
        /// <returns></returns>
        public Result<string> ReadOne(int timeout)
        {
            socket.ReceiveTimeout = timeout;
            socket.SendTimeout = timeout;
            AppendInfo(Name, "扫码");
            var result = WriteThenRead(CmdStart);
            AppendResult(Name, result.Value ?? "空");
            return result;
        }
        string CmdStart => "TRIGGER";//开始扫描
        string CmdEnd => "UNTRIG";//取消扫描
    }
}
